<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <style type="text/css">
        .layui-tab-content {
            padding: 0;/*layui-tab-content:默认有padding: 10px;的值，因为iframe的绝对定位脱离文档流，所以会存在20px的空白空间*/
        }
        .show-frame {
            top: 50px!important;
            /*默认.layui-layout-admin .layui-body {
                top: 60px;
                bottom: 44px;
            }*/
            overflow: hidden;/*消除浏览器最右边的滚动条*/
        }
        .frame {
            position: absolute;
            padding: 10px;/*与layui-footer隔开一段距离*/
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">layui 后台布局</div>

        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <%--<img src="http://t.cn/RCzsdCq" class="layui-nav-img">--%>
                </a>
            </li>
            <li class="layui-nav-item"><a href="/logout">退了</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test" id="menuMax">

            </ul>
        </div>
    </div>


    <div class="layui-body">
        <div class="layui-tab" lay-filter="demo" lay-allowClose="true">
            <ul class="layui-tab-title">
                <li class="layui-this">欢迎登陆</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show" align="center">欢迎登陆后台管理系统</div>
            </div>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>
<script src="layui/layui.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>

<script id="menuTpl" type="text/html">
    {{#  layui.each(d, function(index, obj){ }}
    <li class="layui-nav-item ">
        <a class="" href="javascript:;">{{ obj.menuName }}</a>
        <dl class="layui-nav-child">
            {{#  layui.each(obj.resList, function(index, item){ }}
            <dd><a href="javascript:void(0);" class="menu" url="{{ item.menuUrl }}" id="{{ item.menuId }}">{{ item.menuName }}</a></dd>
            {{#  }); }}
        </dl>
    </li>
    {{#  }); }}
</script>
<script>

    //ajax操作
    $.ajax({
        url:"cmfzMenu/selectMenu",
        dataType:"json",
        async:false,
        success:function(data){
            layui.use("laytpl",function(){
                var laytpl=layui.laytpl;
                var getTpl = menuTpl.innerHTML
                    ,view = document.getElementById('menuMax');
                laytpl(getTpl).render(data, function(html){
                    view.innerHTML = html;
                });
            })
        }
    });
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;
        $(".menu").click(function(){
            if($("[lay-id="+$(this).attr("id")+"]").size()<1) {
                var a='${pageContext.request.contextPath}';
                element.tabAdd("demo", {
                    title: $(this).html()
                    , content: '<iframe class="frame" src="'+a+$(this).attr("url")+'"></iframe>' //支持传入html
                    , id: $(this).attr("id")
                });
            }
            //切换到该选项卡里面
            element.tabChange("demo",$(this).attr("id"));
        });
    });
</script>
</body>
</html>
